package org.springsecuritylearn.repository.jvm.lession1.demo1;

import java.lang.ref.WeakReference;

/** 弱引用测试
 * @author hyf
 * @Title: ${file_name}
 * @Package org.springsecuritylearn.repository.jvm.lession1.demo1
 * @Description: ${todo}
 * @date 2018/5/5上午10:47
 */
public class WeakRef {
    public static class User{
        public int id;
        public String name;

        public  byte[] bytes;

        public User(int id, String name) {
            this.id = id;
            this.name = name;
        }

        public User(int id, String name, byte[] bytes) {
            this.id = id;
            this.name = name;
            this.bytes = bytes;
        }

        @Override
        public String toString() {
            return "User{" +
                    "id=" + id +
                    ", name='" + name + '\'' +
                    '}';
        }
    }

    public static void main(String[] args) {
        User u=new User(1,"ggggggg");
        WeakReference<User> userWeakReference=new WeakReference<User>(u);
        u=null;
        System.out.println(userWeakReference.get());
       // u=userWeakReference.get();
        System.gc();
        System.out.println("After GC");
        System.out.println(userWeakReference.get());


    }







}
